// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023. All rights reserved.
 * Author: Huawei OS Kernel Lab
 * Create: Thu Aug 15 16:14:23 2023
 */

#include <linux/notifier.h>

static BLOCKING_NOTIFIER_HEAD(suspend_chain_head);

int suspend_error_inject_register(struct notifier_block *nb)
{
	return blocking_notifier_chain_register(&suspend_chain_head, nb);
}
EXPORT_SYMBOL(suspend_error_inject_register);

int suspend_error_inject_unregister(struct notifier_block *nb)
{
	return blocking_notifier_chain_unregister(&suspend_chain_head, nb);
}
EXPORT_SYMBOL(suspend_error_inject_unregister);

int pm_suspend_should_fail(unsigned long val, int *error)
{
	int res;

	/* If notify-list is empty, the return value is 0. When notify-list
	is not empty and no value is set, the return value is 1. */
	res = blocking_notifier_call_chain(&suspend_chain_head, val, NULL);
	*error = res;
	if (res != 0 && res != 1)
		return true;
	return false;
}
EXPORT_SYMBOL(pm_suspend_should_fail);

